{include file="public/header"/}
</head>
<body>
<div class="layui-form" id="LAY-component-layer-list">
  <div class="layui-fluid">
    <div class="layui-col-md12 pd83">
      <div class="layui-card hideshadow">
        <div class="layui-tab layui-tab-card hideshadow">
          <ul class="layui-tab-title">
            <li class="layui-this">常规选项</li>
            <li>高级选项</li>
          </ul>
          <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
              <div class="layui-row">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><b class="pcfts">*</b> 栏目名称</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                         <input type="text" name="typename" id="typename" value="" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><b class="pcfts">*</b> 目录名称</label>
                        <div class="layui-input-inline pcfcms_layui-input-inline">
                         <input type="text" value="" name="dirname" id="dirname" class="layui-input" lay-verify="check_dirname" onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9_]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\[^a-zA-Z0-9_]/g,''));">
                        </div>
                    </div>
                    <div class="layui-form-item">
                      <label class="layui-form-label"><b class="pcfts">*</b> 内容模型</label>
                      <div class="layui-input-inline">
                       <select name="current_channel" id="current_channel" lay-verify="required" lay-filter="current_channel">
                          {volist name="channeltype_list" id="vo"}
                          <option value="{$vo.id}" data-nid="{$vo.nid}" selected="true">{$vo.title}</option>
                          {/volist}
                        </select>
                        <div class="layui-form-inline2" style="margin-left:0px;" id="notic_current_channel"></div>
                      </div>
                    </div>
                    {gt name="$parent_id" value="0"}
                    <div class="layui-form-item">
                      <label class="layui-form-label">所属栏目</label>
                      <div class="layui-input-inline">
                          <div style="line-height:38px;">{$ptypename}</div>
                      </div>
                    </div>
                    {/gt}
                    <div class="layui-form-item none">
                      <label class="layui-form-label">文件保存目录</label>
                      <div class="layui-input-inline pcfcms_layui-input-inline">
                          <input type="text" value="{$predirpath}" name="dirpath" id="dirpath" class="layui-input" onkeyup="this.value=this.value.replace(/[^0-9a-zA-Z\/-]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^0-9a-zA-Z\/-]/g,''));">
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <label class="layui-form-label">隐藏栏目</label>
                      <div class="layui-input-inline pcfcms_layui-input-inline">
                          <input type="checkbox" lay-filter="is_hidden" lay-skin="switch" lay-text="是|否">
                          <input type="hidden" name="is_hidden" value="0" />
                      </div>
                    </div>
              </div>
            </div>
            <div class="layui-tab-item">
              <div class="layui-row">
                  <div class="layui-form-item">
                    <label class="layui-form-label">外部链接</label>
                    <div class="layui-input-inline pcfcms_layui-input-inline">
                        <input type="checkbox" lay-filter="is_part" lay-skin="switch" lay-text="开启|关闭">
                        <input type="hidden" name="is_part" value="0" />
                    </div>
                  </div>
                  <div class="layui-form-item none" id="is_part1">
                    <label class="layui-form-label"><b class="pcfts">*</b>URL网址</label>
                    <div class="layui-input-inline pcfcms_layui-input-inline">
                      <input type="text" name="typelink" value="" lay-verify="check_typelink" placeholder="http://" class="layui-input">
                    </div>
                  </div>

                  <div class="layui-form-item">
                    <label class="layui-form-label">英文别名</label>
                    <div class="layui-input-inline pcfcms_layui-input-inline">
                      <input type="text" name="englist_name" value="" class="layui-input">
                    </div>
                  </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">栏目图片</label>
                      <div class="layui-input-inline auto">
                      <ul class="layout">
                        <li>
                        <input name="litpic" id="litpic" placeholder="图片地址" value="" class="layui-input inp inp_logo">
                        <img id="img_litpic" src="{:get_default_pic()}" class="none">
                        </li>
                        <li style="margin-top:3px;margin-left:5px;">
                          <div class="layui-btn-group">
                            <input type="button" value="上传图片" class="layui-btn layui-btn-sm pcfcms-upload" lay-data="{number:1,pcf_inputId:'litpic',pcf_savepath:'allimg'}">
                            <input type="button" value="选择图片" class="layui-btn layui-btn-sm" onClick="GetPictureFolder(1,'litpic');">
                            <input type="button" value="预览" class="layui-btn layui-btn-sm" onclick="BigImages($('#img_litpic').attr('src'));">
                            <input type="button" value="清除" class="layui-btn layui-btn-sm layui-btn-warm" data-inputid="litpic" onclick="DelImages(this);">
                          </div>
                        </li>
                      </ul>
                      </div>
                  </div>

                  <div class="layui-form-item" id="dl_templist">
                    <label class="layui-form-label" for="templist"><b class="pcfts">*</b>列表模板</label>
                    <div class="layui-input-inline">
                       <select name="templist" id="templist" lay-verify="check_templist">
                      </select>
                    </div>
                    <div class="layui-input-inline layui-btn-container">
                      <div class="layui-form-inline2">列表模板命名规则：<br/>lists_<font class="font_nid">模型标识</font>.html
                      <br/>lists_<font class="font_nid">模型标识</font>_自定义.html</div>
                    </div>
                     <div class="layui-input-inline layadmin-layer-demo" style="margin-top:3px;">
                       <a class="layui-btn layui-btn-sm" data-value="lists" data-type="newtpl">新建模板</a>
                    </div>
                  </div>

                  <div class="layui-form-item" id="dl_tempview">
                    <label class="layui-form-label" for="tempview"><b class="pcfts">*</b>文档模板</label>
                    <div class="layui-input-inline">
                       <select name="tempview" id="tempview" lay-verify="check_tempview">
                      </select>
                    </div>
                    <div class="layui-input-inline layui-btn-container">
                      <div class="layui-form-inline2 ">文档模板命名规则：<br/>view_<font class="font_nid">模型标识</font>.html
                      <br/>view_<font class="font_nid">模型标识</font>_自定义.html</div>
                    </div>
                     <div class="layui-input-inline layadmin-layer-demo" style="margin-top:3px;">
                       <a class="layui-btn layui-btn-sm" data-value="view" data-type="newtpl">新建模板</a>
                    </div>
                  </div>

                  <div class="layui-form-item">
                    <label class="layui-form-label">SEO标题</label>
                    <div class="layui-input-inline pcfcms_layui-input-inline">
                      <input type="text" name="seo_title" value="" class="layui-input">
                    </div>
                  </div>

                  <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">SEO关键字</label>
                    <div class="layui-input-inline pcfcms_layui-input-inline">
                      <textarea name="seo_keywords" class="layui-textarea"></textarea>
                    </div>
                  </div>

                  <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">SEO描述</label>
                    <div class="layui-input-inline pcfcms_layui-input-inline">
                      <textarea name="seo_description" class="layui-textarea"></textarea>
                    </div>
                  </div>
                  <input type="hidden" name="grade" id="grade" value="{$grade}">
                  <input type="hidden" name="parent_id" id="parent_id" value="{$parent_id}">
              </div>
            </div>
            <div class="pcfclear"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="pcfclear"></div>
  </div>
  <div class="submit-info text-center">
      <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
  </div>
</div>
{include file="public/footer"/}
<script>
  layui.use(['layer', 'form', 'table', 'util','element'], function () {
      var $ = layui.$,
      element = layui.element,
      layer = layui.layer,
      form = formNew = layui.form;
      element.render();
      var parentObj = parent.layer.getFrameIndex(window.name);
      var templateList = {$templateList|raw};
      ajax_get_template();
      form.verify({
        check_typename: function(value, item){
          if(value == '' || undefined == value){
              tabchange(0)
              return '必填项不能为空';
          }
        },
        check_dirname: function(value, item){
          if(value == '' || undefined == value){
              return '必填项不能为空';
          } 
          var patrn = /^\d+$/;
          if (patrn.test(value) == true) {
              tabchange(0)
              return '目录名称不能为纯数字！';
          }
        },
        check_typelink: function(value, item){
          if ($('input[name=is_part]').val() == 1) {
              if(value == ''){
                  tabchange(1);
                  return '外部链接不能为空！';
              }
          }
        },
        check_templist: function(value, item){
          if(value == '' || undefined == value){
              tabchange(1)
              return '请选择列表模板';
          }
        },
        check_tempview: function(value, item){
          var channel = parseInt($('#current_channel').find('option:selected').val());
          var js_allow_channel_arr = {$js_allow_channel_arr};
          if($('#tempview').val() == '' && $.inArray(channel, js_allow_channel_arr) != -1){
              tabchange(1)
              return '请选择文档模板';
          }
        }
      });

      // 监听开关
      form.on('switch', function(data){
          var elemId = data.elem.attributes['lay-filter']['nodeValue'];
          if (data.elem.checked) {
            this.value = 1;
          } else {
            this.value = 0;
          }
          $("input[name='"+elemId+"']").val(this.value);
      });

      // 监听开关
      form.on('switch(is_part)', function(data){
          var elemId = data.elem.attributes['lay-filter']['nodeValue'];
          if (data.elem.checked) {
            this.value = 1;
            $('#is_part1').show();
          } else {
            this.value = 0;
            $('#is_part1').hide();
          }
          $("input[name='"+elemId+"']").val(this.value);
      });

      form.on('select(current_channel)', function(data){
          ajax_get_template();
      });

      $('#LAY-component-layer-list .layadmin-layer-demo .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] && active[type].call(this);
      });

      //触发事件
      var active = {
        newtpl: function(){
          var type = $(this).data('value');
          var nid = $('#current_channel').find('option:selected').attr('data-nid');
          var url = "{:url('/arctype/ajax_newtpl')}";
          if (url.indexOf('?') > -1) {
              url += '&';
          } else {
              url += '?';
          }
          url += 'type='+type+'&nid='+nid;
          if ('lists' == type) {
              var title = '新建列表模板';
          } else {
              var title = '新建文档模板';
          }
          var iframes = layer.open({
              type: 2,
              title: title,
              fixed: true,
              shadeClose: false,
              shade: 0.3,
              area: ['100%', '100%'],
              content: url
          });
        }
      };

      //监听提交
      form.on('submit(formSubmit)', function(data){
          layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:3600000});
          $.ajax({
              type : 'post',
              url : "{:url('/arctype/add')}",
              data : data.field,
              dataType : 'json',
              success : function(res){
                  layer.closeAll('loading');
                  if(res.status){
                      layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                          parent.window.location.href = res.url;
                      });
                  }else{
                      layer.msg(res.msg, {icon: 2, time: 1000});
                  }
              },
              error: function(e){
                  layer.closeAll('loading');
                  layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
              }
          });
      });

      function tabchange(tabIndex)
      {
          var tabObj = $('div.layui-tab ul.layui-tab-title');
          tabObj.find('li').each(function(){
              $(this).removeClass('layui-this');
          });
          $(tabObj.find('li').get(tabIndex)).addClass('layui-this');
          $('.layui-tab-item').removeClass('layui-show');
          $($('.layui-tab-item').get(tabIndex)).addClass('layui-show');
      }

      function ajax_get_template() 
      {
          var obj = $('#current_channel');
          var channel = parseInt($(obj).find('option:selected').val());
          var js_allow_channel_arr = {$js_allow_channel_arr};
          $('#notic_current_channel').html('');
          $.ajax({
              url: "{:url('/arctype/ajax_getTemplateList')}",
              type: 'GET',
              dataType: 'JSON',
              success: function(res){
                  if (res.status) {
                      templateList = res.data.templateList;
                  }
              }
          });
          if (templateList[channel] == undefined || templateList[channel] == ''){
              layer.msg("模板文件不存在！", {icon: 2, time: 1000});
              return false;
          } else if(templateList[channel]['msg'] != '') {
              $('#notic_current_channel').html(templateList[channel]['msg']);
          }
          $('#templist').html(templateList[channel]['lists']);
          if($.inArray(channel, js_allow_channel_arr) == -1){
              if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<b class="pcfts">*</b>单页模板');
              }
              $('#dl_tempview').hide();
          }else{
              $('#dl_templist').find('label[for=templist]').html('<b class="pcfts">*</b>列表模板');
              $('#dl_tempview').show();
          }
          $('#tempview').html(templateList[channel]['view']);
          $('.font_nid').html(templateList[channel]['nid']);
          form.render();
      }
  });
  var formNew;//新建模板返回刷新用
  function formRender(){
    formNew.render();
  }
</script>
</body>
</html>